package org.timemachine.manager;

import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.Vector;

import javax.persistence.Entity;

import org.timemachine.Change;
import org.timemachine.tool.ClassHelperImpl;
import org.timemachine.tool.ClassLoaderHelperImpl;
import org.timemachine.tool.spi.ClassHelper;

public class TimeMachineManager {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}
	
	private ClassHelper classHelper;
	
	private Vector<Class<?>> allClazzes;
	
	private Set<Class<?>> clazzesWithAnnotations;
	
	private List<Class<?>> clazzList;
	
	
	
	public Vector<Class<?>> getAllClazzes() {
		return allClazzes;
	}



	public void setAllClazzes(Vector<Class<?>> allClazzes) {
		this.allClazzes = allClazzes;
	}



	public Set<Class<?>> getClazzesWithAnnotations() {
		return clazzesWithAnnotations;
	}



	public void setClazzesWithAnnotations(Set<Class<?>> clazzesWithAnnotations) {
		this.clazzesWithAnnotations = clazzesWithAnnotations;
	}





	public List<Class<?>> getClazzList() {
		return clazzList;
	}



	public void setClazzList(List<Class<?>> clazzList) {
		this.clazzList = clazzList;
	}



	@SuppressWarnings("unchecked")
	public void standUp() throws Exception {
		
		ClassLoaderHelperImpl cLoaderHelper = new ClassLoaderHelperImpl();
		classHelper = new ClassHelperImpl();
		
		allClazzes = (Vector<Class<?>>) classHelper.findFieldValue(cLoaderHelper.getLoader(), cLoaderHelper.getLoaderClass(), "classes");
		
		Set<Class<? extends Annotation>> annos = new HashSet<Class<? extends Annotation>>();
		annos.add(Entity.class);
		annos.add(Change.class);
		
		clazzesWithAnnotations = classHelper.findClassesWithAnnotation(allClazzes, annos);
		
		clazzList = new ArrayList<Class<?>>();
		for (Class<?> class1 : clazzesWithAnnotations) {
			 System.out.println("Classes : " + class1.toString());
			 clazzList.add(class1);
		}

	}

}
